package com.servlet;

import com.dao.StudenCla;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/DeleteServlet2")
public class DeleteClass extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            deleteCode(req, resp);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    //删除
    private void deleteCode(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException, SQLException {
        Integer id = Integer.parseInt(req.getParameter("id"));
        StudenCla studenCla = new StudenCla();
        studenCla.deleteData(id);
        req.getRequestDispatcher("checktest").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
